#include "timeutil.h"
#include <assert.h>
#include <time.h>
#include <string.h>

long int elapsed (const struct timespec* since)
{
  struct timespec now;
  assert(since != 0);
  
  clock_gettime(CLOCK_MONOTONIC, &now);
  return now.tv_nsec - since->tv_nsec;
}

void perai (long int nanoseconds)
{
  struct timespec wait;
  memset(&wait, 0, sizeof(wait));
  if (nanoseconds == 0) return;
  wait.tv_sec = 0;
  wait.tv_nsec = nanoseconds;
  nanosleep(&wait, NULL);
}

